package com.pirestupppai.widgets.dialog;

import android.content.Context;
import android.view.View;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.pirestupppai.R;
import com.pirestupppai.base.BaseDialog;
import com.pirestupppai.bean.FeedItem;
import com.pirestupppai.network.NetworkRequest;
import com.pirestupppai.network.TupaiSubscriber;
import com.pirestupppai.utils.Utils;

import butterknife.BindView;

/**
 * 举报
 *
 * @author: xiaoluo
 * @date: 2017-04-25 18:02
 */
public class ReportDialog extends BaseDialog {

    @BindView(R.id.report_reason_one)
    TextView reasonOneTv;
    @BindView(R.id.report_reason_two)
    TextView reasonTwoTv;
    @BindView(R.id.report_reason_three)
    TextView reasonThreeTv;
    @BindView(R.id.report_close_layout)
    RelativeLayout closeLayout;

    private FeedItem mFeedItem;

    public ReportDialog(Context context, FeedItem feedItem) {
        super(context, R.style.CustomDialogStyle);
        mFeedItem = feedItem;
    }

    @Override
    protected int loadParentLayout() {
        return R.layout.dialog_report;
    }

    @Override
    protected boolean atBottom() {
        return true;
    }

    @Override
    protected void initViews() {

    }

    @Override
    protected void initListeners() {
        reasonOneTv.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                reasonOneTv.setClickable(false);
                report(reasonOneTv.getText().toString());
            }
        });

        reasonTwoTv.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                reasonTwoTv.setClickable(false);
                report(reasonTwoTv.getText().toString());
            }
        });

        reasonThreeTv.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                reasonThreeTv.setClickable(false);
                report(reasonThreeTv.getText().toString());
            }
        });

        closeLayout.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                dismiss();
            }
        });
    }


    private void report(String reason) {
        Utils.showToast("举报成功");
        dismiss();
        NetworkRequest.getInstance().reportFeed("post", mFeedItem.getId(), reason, mContext,
                new TupaiSubscriber<Boolean>(mContext) {
                    @Override
                    protected void requestSuccess(Boolean aBoolean) {
                        Utils.showToast("举报成功");
                        dismiss();
                    }

                    @Override
                    protected void requestError(String error) {
                        Utils.showToast("举报失败，请稍后再试");
                        reasonOneTv.setClickable(true);
                        reasonTwoTv.setClickable(true);
                        reasonThreeTv.setClickable(true);
                    }
                });
    }
}

